package com.qiaofang.collectmanage.service.util;

import java.lang.reflect.Field;
import java.util.Map;

/**
 * @Author: GJ
 * @Date: 2018/4/13 18:17
 * @Description:
 */
public class BeanUtil {

    public static <T>T  mapperObj(Map map, Class<T> t) throws IllegalAccessException, InstantiationException {
        if(map==null||map.size()==0){
            return t.newInstance();
        }
        Object tobj=t.newInstance();
        for(Object key:map.keySet()){
            try{
                t.getDeclaredField((String) key);
                Field field =t.getDeclaredField((String) key);
                field.setAccessible(true);
                field.set(tobj, map.get(key));
            }catch (NoSuchFieldException e){
                continue;
            }

        }
        return (T) tobj;
    }
}
